<template>
    <div class="order">
        <!-- 查询条件 -->
        <el-form :inline="true" :model="formInline" class="demo-form-inline" size="mini">
            <el-form-item label="订单编号">
                <el-input v-model="formInline.orderNo" placeholder="订单编号"></el-input>
            </el-form-item>
            <el-form-item label="店铺名称">
                <el-input v-model="formInline.shopName" placeholder="店铺名称"></el-input>
            </el-form-item>
            <el-form-item label="订单状态">
                <el-select v-model="formInline.orderStatus" placeholder="请选择">
                    <el-option label="全部" value=""></el-option>
                    <el-option
                            v-for="(value,key) in statusList"
                            :key="key"
                            :label="value"
                            :value="key">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-date-picker
                        v-model="formInline.dateArr" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"
                        placeholder="选择时间范围"
                        value-format="yyyy-MM-dd">
                </el-date-picker>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <!--列表-->
        <el-table  :data="sysParamData" stripe highlight-current-row v-loading="listLoading" style="width: 100%">
            <el-table-column label="订单编号" width="220" align="center">
                <template slot-scope="scope">
                    <router-link :to="{path:'/order_detail', query:{ orderId: scope.row.id }}">
                        {{ scope.row.orderNo }}
                    </router-link>
                </template>
            </el-table-column>
            <el-table-column prop="shopName" label="店铺名称" align="center"></el-table-column>
            <el-table-column prop="area" label="所属区域" align="center"></el-table-column>
            <el-table-column prop="createDate" label="订单时间" align="center"></el-table-column>
            <el-table-column prop="totalCount" label="商品数量（件）" align="center"></el-table-column>
            <el-table-column prop="status" label="订单状态" :formatter="formatState" align="center"></el-table-column>
            <el-table-column label="操作" width="120" align="center">
                <template slot-scope="scope" v-if="scope.row.status==3||scope.row.status==4">
                    <el-button size="mini" type="primary" @click="uploadPic(scope.row.id)">上传收货单</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-pagination
                    background
                    layout="prev, pager, next" :page-size="10"
                    :total="total"
                    style="float:right;"
                    @current-change="changePage"
                    :current-page.sync="currentPage">
            </el-pagination>
        </el-col>
    </div>
</template>
<script>
    import * as api from  '../../api/enjoylove_api'
    export default {
        data() {
            return {
                formInline:{
                    orderNo:'',
                    shopName:'',
                    orderStatus:'',
                    dateArr:'',
                    startDate:'',
                    endDate:'',
                },
                listLoading: false,
                currentPage: 1,
                total: 0,
                sysParamData: [],
                statusList:{}

            }
        },
        methods: {
            onSubmit() {
                this.currentPage =1;
                this.getData();
            },
            formatState(row){
                var stateString = '';
                if(row.status==1){
                    stateString = '待付款'
                }else  if (row.status==2){
                    stateString = '待发货'
                }else  if (row.status==3){
                    stateString = '待收货'
                }else  if (row.status==4){
                    stateString = '已完成'
                } else {
                    stateString = '已取消'
                }
                return stateString;
            },
            getData(){
                this.listLoading = true;
                if (this.formInline.dateArr==null){
                    this.formInline.dateArr =''
                }
                let param ={
                    page:this.currentPage,
                    shopName:this.formInline.shopName,
                    orderStatus:this.formInline.orderStatus,
                    orderNo:this.formInline.orderNo,
                    startDate:this.formInline.dateArr[0],
                    endDate:this.formInline.dateArr[this.formInline.dateArr.length-1],
                }
                api.getOrderList(param).then((res)=>{
                    this.listLoading = false;//停止加载
                    var _resData  =JSON.parse(res.data) ;
                    if(!_resData.status){
                        if(_resData.success){
                            //成功
                            this.sysParamData = _resData.data.orders.content;
                            this.total = _resData.data.orders.totalElements;
                        }else {
                            this.$message.error(_resData.message);
                        }
                    }else{
                        if(_resData.status == 401){
                            this.$router.push('/login');
                        }
                    }
                });
            },
            getOrderStatusList(){
                api.getOrderStatusList({}).then((res)=>{
                    var _resData  =JSON.parse(res.data) ;
                    if(!_resData.status){
                        if(_resData.success){
                            this.statusList = _resData.data.orderStatus;
                        }else {
                            this.$message.error(_resData.message);
                        }
                    }else {
                        if (_resData.status == 401) {
                            this.$router.push('/login');
                        }
                    }
                });
            },
            //选择页码
            changePage(val){
                this.currentPage = val;
                this.getData();
            },
            //上传图片
            uploadPic(id){
                this.$router.push('/order_detail?orderId='+id);
            }


        },
        mounted() {
            this.$nextTick(function () {
                this.getData();
                this.getOrderStatusList();
            });

        }

    }
</script>